require 'View/UIBase/UIBase'

UICommonNewChapter = UIBase.New(PanelNames.UICommonNewChapter)

function UICommonNewChapter.Init(fun)
    UICommonNewChapter.callbackFun = fun;
    UIBase.Init(UICommonNewChapter,func);
end

-- 创建回调
function UICommonNewChapter:OnCreate()
    self.drawWrapper = GoWrapper.New()

    self.textChapter = self:GetChild("textChapter");
    self:RegisterOnClick(self:GetChild("clickPanel"),self.OnClose);
    --AudioManager.SetSwitch("fight_result", "win_chapter")
    AudioManager.Play(AudioManager.Play_New_Chapter)
end

-- 显示
function UICommonNewChapter:OnEnable()
    self:Refresh();
end

function UICommonNewChapter:Refresh()
    self:UpdateData();
end

function UICommonNewChapter:UpdateData()
    local nextTableData = logicMgr.MapManager.GetMapcfgByID(logicMgr.MapManager.getNextStage());
    if nextTableData ~= nil then
        --"第"..nextTableData.f_ChapterId.."章·"..
        self.textChapter.text = getLanguage(G.dataTable["t_chapter"][tostring(nextTableData.f_ChapterId)].f_ChapterName);
    else
        self:OnClose();
    end
end

-- 关闭
function UICommonNewChapter:OnClose()
    self:OnBack();
    if self.callbackFun ~= nil then
        self.callbackFun();
    end
end

-- 隐藏
function UICommonNewChapter:OnDisable()
end

-- 卸载
function UICommonNewChapter:OnDestroy()
end

return UICommonNewChapter